﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MaiStatistic : System.Web.UI.Page
{
    public string Sqlstr = "";
    public string flag = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.ddlStore.Items.Add(new ListItem("--全部--"));
            this.ddlDepartment.Items.Add(new ListItem("--全部--"));
            Bind();
        }
        
    }
    public void Bind()
    {
        DataSet ds1 = DB.reDs("select Title from tb_BigType where Type='仓库'");
        this.ddlStore.DataSource = ds1;
        ddlStore.DataTextField = "Title";
        ddlStore.DataBind();
        DataSet ds2 = DB.reDs("select Title from tb_BigType where Type='部门'");
        this.ddlDepartment.DataSource = ds2;
        ddlDepartment.DataTextField = "Title";
        ddlDepartment.DataBind();
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (this.radButtonStore.Checked == true)
        {
            if (this.ddlStore.SelectedValue != "--全部--")
            {
                if (flag == "0")
                {
                    Sqlstr = Sqlstr + " where " + "B.StorePlace='" + this.ddlStore.SelectedItem.ToString() + "'";
                }
                else
                {
                    Sqlstr = Sqlstr + "  and  " + "B.StorePlace='" + this.ddlStore.SelectedItem.ToString() + "'";
                }
                flag = "1";
            }
            else
            {
                Response.Write("<script>alert('请选择仓库！');location='MaiStatistic.aspx'</script>");
            }

        }
        if (this.radButtonDepartment.Checked == true)
        {
            if (this.ddlDepartment.SelectedValue != "--全部--")
            {
                if (flag == "0")
                {
                    Sqlstr = Sqlstr + " where " + "B.Department='" + this.ddlDepartment.SelectedItem.ToString() + "'";
                }
                else
                {
                    Sqlstr = Sqlstr + "  and  " + "B.Department='" + this.ddlDepartment.SelectedItem.ToString() + "'";
                }
                flag = "1";
            }
            else
            {
                Response.Write("<script>alert('请选择部门！');location='MaiStatistic.aspx'</script>");
            }
        }
        if (this.radButtonAll.Checked == true)
        {
            if (this.ddlStore.SelectedValue != "--全部--")
            {
                if (flag == "0")
                {
                    Sqlstr = Sqlstr + " where " + "B.StorePlace='" + this.ddlDepartment.SelectedItem.ToString() + "'";
                }
                else
                {
                    Sqlstr = Sqlstr + "  and  " + "B.StorePlace='" + this.ddlDepartment.SelectedItem.ToString() + "'";
                }
                flag = "1";
            }
            if (this.ddlDepartment.SelectedValue != "--全部--")
            {
                if (flag == "0")
                {
                    Sqlstr = Sqlstr + " where " + "B.Department='" + this.ddlStore.SelectedItem.ToString() + "'";
                }
                else
                {
                    Sqlstr = Sqlstr + "  and  " + "B.Department='" + this.ddlStore.SelectedItem.ToString() + "'";
                }
                flag = "1";
            }
        }
        DataSet ds = DB.reDs("select * from tb_Service as A inner join tb_Gdzc as B on A.WzID=B.GdzcID" + Sqlstr);
        this.gvStatistic.DataSource = ds;
        this.gvStatistic.DataBind();
    }
}
